<!--
	作者：956911785@qq.com
	时间：2019年8月1日17:44:32
	描述：书籍分类-添加
-->

<template>
	<Modal :title="title" v-model="modal0" width="500px">
		<Form ref="params" :model="params" :rules="ruleValidate" :label-width="100" label-position="left">
			<div style="width:100%;height:150px; overflow-y: hidden;">
		      	<div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 80%;text-align: left;float: left;" align="left">
				        <FormItem  label="上级分类">
				        	<Select v-model="params.pid" style="width:80%;float:left;" clearable>
						        <Option v-for="item in pclass" :value="item.CLASSID" :key="item.CLASSNAME">{{ item.CLASSNAME }}</Option>
						    </Select>
		        		</FormItem>
		        	</div>
		        </div>

				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 80%;text-align: left;float: left;" align="left">
				        <FormItem  prop="classname" label="分类名称">
				        	<Input v-model="params.classname" placeholder="请输入分类名称" clearable style="width: 70%"></Input>
		        		</FormItem>
		        	</div>
		      	</div>
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>

	
	export default {
		name:"tconent",
		props: {
    		teas:{
    			type:Object,	
    			default: function() {
					return null
				}
    		},
    		title:{
    			type:String,	
    		},
    	},
		data() {
			//长度控制
			const lenPass = (rule, str, callback) => {
			  if(str.length>rule.length){
			  	 callback(new Error('字符串长度在1-'+rule.length+'之间！'));
			  }
			  return callback();
			};
		
			return {
				ruleValidate: {
		            classname: [
		                {required: true, message: '请输入分类名称！', trigger: 'blur'},
		                {length:30,validator:lenPass,trigger:'blur'}
		            ]
		        },   
                modal0:false,
                params:{
                	classid:'',
                	pid:'', 
					classname:'',
                },
                pclass:[],
			}
		},
		methods: {
			addsave:function(){
				this.$refs.params.validate((valid) => {
					if (valid){
						const params={...this.params};
						this.$emit("addsave",params);
                    }
               })
	        }, 
            closeModal(){
	      	    this.modal0 = false;
	      	    this.resetpar();
	        },
	        resetpar(){
	        	this.params={
	        		classid:'',
	        		pid:'', 
					classname:'',
				};
	        },
	        getPidClass(){
	        	//上级分类查询
	        	 this.$http.post("/host/readbook/sjfl/getPidClass.html")
				.then(result => {
					this.pclass=result;
				});
	        },

		},
		mounted() {
		},
		watch:{
			modal0(news,olds){
				if(!news){
					 this.resetpar();
				}else{
					this.params={...this.teas};
					this.getPidClass();
				}
			}
		},
		computed: {
		
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



